package o;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnShowListener;
import android.view.View;
import android.widget.Button;
import com.huawei.hwid.core.constants.HwAccountConstants;
import o.dky.j;

public class BaseAlertDialog {
    private Builder ʻ;
    private OnShowListener ʼ;
    private AlertDialog ʽ;
    protected cks ˊ;
    private CharSequence ˋ;
    private String ˎ;
    protected Context ˏ;
    private ewe ॱ = null;

    public enum a {
        CONFIRM,
        NEUTRAL,
        CANCEL
    }

    protected BaseAlertDialog(Context context, String str, CharSequence charSequence) {
        this.ˏ = context;
        this.ˎ = str;
        this.ˋ = charSequence;
        this.ʻ = new Builder(context);
        this.ʻ.setTitle(this.ˎ);
        this.ʻ.setPositiveButton(j.ˊॱ, new OnClickListener(this) {
            final /* synthetic */ BaseAlertDialog ˎ;

            {
                this.ˎ = r1;
            }

            public void onClick(DialogInterface dialogInterface, int i) {
                if (this.ˎ.ˊ != null) {
                    this.ˎ.ˊ.enableNetworking();
                }
            }
        });
        this.ʻ.setNegativeButton(j.ͺ, new OnClickListener(this) {
            final /* synthetic */ BaseAlertDialog ॱ;

            {
                this.ॱ = r1;
            }

            public void onClick(DialogInterface dialogInterface, int i) {
                if (this.ॱ.ˊ != null) {
                    this.ॱ.ˊ.upgrade();
                }
            }
        });
        this.ʻ.setMessage(this.ˋ);
    }

    public static BaseAlertDialog ˋ(Context context, String str, CharSequence charSequence) {
        if ((context instanceof Activity) && ((Activity) context).isFinishing()) {
            return new ckz(context, str, charSequence);
        }
        return new BaseAlertDialog(context, str, charSequence);
    }

    public void ˊ(View view) {
        if (this.ʻ != null) {
            this.ʻ.setMessage(null);
            this.ʻ.setView(view);
        }
    }

    public void ॱ(boolean z) {
        if (this.ʽ != null) {
            this.ʽ.setCanceledOnTouchOutside(z);
        }
    }

    public void ॱ(a aVar, int i) {
        if (this.ˏ != null) {
            ॱ(aVar, this.ˏ.getString(i));
        }
    }

    public void ॱ(a aVar, String str) {
        Button button = null;
        if (this.ʽ != null) {
            if (aVar == a.CONFIRM) {
                button = this.ʽ.getButton(-1);
            } else if (aVar == a.CANCEL) {
                button = this.ʽ.getButton(-2);
            } else if (aVar == a.NEUTRAL) {
                button = this.ʽ.getButton(-3);
            }
            if (button != null) {
                button.setText(str);
                button.setAllCaps(true);
                ewb.ˏ(this.ˏ, button, str);
            }
        }
    }

    public void ˏ(a aVar, int i) {
        if (this.ʻ != null) {
            if (aVar == a.CONFIRM) {
                this.ʻ.setPositiveButton(null, null);
            } else if (aVar == a.CANCEL) {
                this.ʻ.setNegativeButton(null, null);
            } else if (i == 0) {
                this.ʻ.setNeutralButton(HwAccountConstants.BLANK, null);
            }
        }
    }

    public void ˊ(View.OnClickListener onClickListener) {
        if (this.ʽ != null) {
            Button button = this.ʽ.getButton(-1);
            if (button != null) {
                button.setOnClickListener(onClickListener);
            }
        }
    }

    public void ˋ(View.OnClickListener onClickListener) {
        if (this.ʽ != null) {
            Button button = this.ʽ.getButton(-2);
            if (button != null) {
                button.setOnClickListener(onClickListener);
            }
        }
    }

    public void ˏ(boolean z) {
        if (this.ʽ != null) {
            Button button = this.ʽ.getButton(-1);
            if (button != null) {
                button.setEnabled(z);
                if (z) {
                    button.setAlpha(1.0f);
                } else {
                    button.setAlpha(0.3f);
                }
            }
        }
    }

    public Dialog ˋ() {
        return this.ʽ;
    }

    public boolean ˎ() {
        return this.ʽ != null && this.ʽ.isShowing();
    }

    public void ˏ() {
        if (this.ʽ != null) {
            try {
                this.ʽ.dismiss();
            } catch (Exception e) {
                Logger.e("BaseAlertDialog", "dialog dismiss exception!");
            }
        }
    }

    public void ˎ(cks o_cks) {
        this.ˊ = o_cks;
    }

    public void ˎ(OnDismissListener onDismissListener) {
        if (this.ʽ != null) {
            this.ʽ.setOnDismissListener(onDismissListener);
        }
    }

    public void ˊ(OnCancelListener onCancelListener) {
        if (this.ʽ != null) {
            this.ʽ.setOnCancelListener(onCancelListener);
        }
    }

    public void ˎ(boolean z) {
        if (this.ʽ != null) {
            this.ʽ.setCancelable(z);
        }
    }

    public void ॱ() {
        if (this.ˏ == null || ((Activity) this.ˏ).isFinishing() || ˎ()) {
            Object obj;
            String str = "BaseAlertDialog";
            StringBuilder append = new StringBuilder(64).append("show dlg error, mContext = ").append(this.ˏ).append(", isShowing() = ").append(ˎ()).append(", mContext.isFinishing is ");
            if (this.ˏ == null) {
                obj = "mContext == null";
            } else {
                obj = Boolean.valueOf(((Activity) this.ˏ).isFinishing());
            }
            Logger.e(str, append.append(obj).toString());
            return;
        }
        try {
            this.ʽ = this.ʻ.create();
            ayw.ˊ(this.ʽ.getWindow());
            this.ʽ.setOnShowListener(this.ʼ);
            this.ʽ.show();
            ewb.ˊ(this.ʽ);
        } catch (Throwable e) {
            Logger.ˋ("BaseAlertDialog", "show dlg error, e: ", e);
        }
    }

    public void ˊ(OnShowListener onShowListener) {
        this.ʼ = onShowListener;
        if (this.ʽ != null) {
            this.ʽ.setOnShowListener(onShowListener);
        }
    }
}
